#include <stdio.h>
#include <sys/wait.h>
#include <sys/types.h>
#include <unistd.h>
void Open()
{
  printf("This is the open computer function\n");
}
void Close()
{
printf("This is the close computer function\n");

}
void Load()
{
  printf("This is the load the computer\n");
}
void (*arr[])()={Open,Close,Load};
void Run()
{
for(int i=0;i<sizeof(arr)/sizeof(arr[0]);i++)
{
arr[i]();
}
}
int main()
{
int ret=fork();
int status=0;
if(ret>0)
{
//父进程
while(1)
{
int waitret=waitpid(ret,&status,WNOHANG);
if(waitret<0)
{
  printf("error\n");
}
if(waitret==0)
{
Run();
}
if(waitret>0)
{
  if(WIFEXITED(status))
  { 
   printf("执行成功，我的退出码是%d\n",WEXITSTATUS(status));
  }
  else
  {
    printf("异常退出，终止信号是%d\n",status&0x7F);
  }
}

sleep(1);
}
}
if(ret==0)
{
//子进程
while(1)
{
printf("I am the child process,my pid is %d,my ppid is %d\n",getpid(),getppid());
sleep(1);
}
}
  return 0;
}
